<?php use_javascript('data/bib.js') ?>
<?php use_javascript('data/researchform.js') ?>

<script type="text/javascript">

    <?php
    if (!empty($bibentry)) {
        $type = $bibentry['type'];

    ?>
        selectedtype = "<?php echo $type; ?>";
    <?php

        while($bibentry->valid()):
            $key = $bibentry->key();
            if ($key == 'author') {
                $author = array();
                foreach ($bibentry->current() as $au) {
                    $author[] = (empty($au['first']) ? '' : $au['first'] . ' ') . $au['last'];
                }
                $value = join(' and ', $author);
            } else {
                $value = $bibentry->current();
            }
    ?>
            entryvalues["<?php echo $key; ?>"] = "<?php echo $value; ?>";

    <?php
            $bibentry->next();
        endwhile;
    }
    ?>

</script>


<form id="research-info-form" method="post"
      action="<?php echo url_for('data/'.($form->getObject()->isNew() ? 'createResearch' : 'updateResearch?id='.$form->getObject()->getId())); ?>"
      enctype="multipart/form-data">

    <?php echo $form->renderGlobalErrors(); ?>

    <div class="subheader research-sub">
        Title and Abstract
    </div>

    <table>
        <tr>
            <td><?php echo $form['id']; ?></td>
        </tr>
        <tr>
            <td><?php echo $form['title']->renderLabel('Title', array('class' => '')) ?></td>
        </tr>
        <tr>
            <td><?php echo $form['title']->renderError(array('class' => 'data')); ?></td>
        </tr>
        <tr>
            <td><?php echo $form['title']->render(array(
                'class' => 'data research_title',
                'required' => 'true'
                )); ?>
            </td>
        </tr>
        <tr>
            <td><?php echo $form['abstract']->renderLabel('', array('class' => '')) ?></td>
        </tr>
        <tr>
            <td><?php echo $form['abstract']->render(array('class' => 'data research_abstract')); ?></td>
        </tr>
        <tr>
            <td></td>
        </tr>

    </table>

    <div class="subheader research-sub">
        Citation
    </div>

    <?php //foreach($bibtex->data as $entry): ?>
        <span><?php
//            echo $entry['title'] ;
//            echo $entry->offsetExists('school') ? $entry['school'] : '';
        ?></span>
        <?php //while($entry->valid()): ?>
            <span><?php
//            $key = $entry->key();
//            if ($key == 'author') {
//                $author = "";
//                foreach ($entry->current() as $au) {
//                    $author .= $au['first'] . ' ' . $au['last'] . ' ';
//                }
//                $value = $author;
//            } else {
//                $value = $entry->current();
//            }
//
//            echo $key.':'. $value;
//
//            $entry->next();
            ?></span>
        <?php //endwhile; ?>
    <?php //endforeach; ?>
    
    <div id="bibtex_fields" class="bibtex-fields">
    </div>
    <input id="startsign" type="hidden" value="&quot;">
    <input id="stopsign" type="hidden" value="&quot;">

    <table>
        <tr>
            <td><?php //echo $form['citation']->renderLabel('Citation', array('class' => '')) ?></td>
        </tr>
        <tr>
            <td><?php echo $form['citation']->renderError(array('class' => 'data')); ?></td>
        </tr>
        <tr>
            <td><?php echo $form['citation']->render(array(
                'class' => 'data research_citation',
                'readonly' => 'true', 
                'style' => 'display: none')); ?>
            </td>
        </tr>
    </table>

    <div class="subheader research-sub">
        Published or Unpublished
    </div>

    <table>
        <tr>
<!--            <td>
                <?php //echo $form['researchstatustyperefid']->renderLabel('Research Type') ?>
            </td>-->
        </tr>
        <tr>
            <td>
                <?php echo $form['researchstatustyperefid']->renderError() ?>
            </td>
        </tr>
        <tr>
            <td>
                <?php echo $form['researchstatustyperefid']->render(array(
                    'class' => 'data',
                    'style' => 'text-transform: capitalize')) ?>
                <p/>
<!--                <p><em>Published research should provide related research paper below.</em></p>-->
            </td>
        </tr>
        <tr class="paper">
            <td>
                <label>Upload paper</label>
            </td>
        </tr>
        <tr class="paper">
            <td>
                <input type="file" name="uploadpaper" id="uploadpaper" class="ui-widget data">
                <?php if (!empty($form->getObject()->researchpaperfilename)): ?>
                <p class="paper-download">Paper: <a href="<?php echo url_for('data/downloadResearchPaper?id='.$form->getObject()->id) ?>"><?php echo $form->getObject()->researchpaperfilename ?></a></p>
                <?php endif; ?>
                <p><em>Uploading new file will replace the existing one.</em></p>
            </td>
        </tr>
        <tr class="paper">
            <td><?php echo $form['researchpaperurl']->renderLabel('Or you may copy paper url links below:', array('class' => '')) ?></td>
        </tr>
        <tr class="paper">
            <td><?php echo $form['researchpaperurl']->render(array('class' => 'data')); ?></td>
        </tr>
    </table>

    <div class="subheader research-sub">
        Remarks
    </div>

    <table>
        <tr>
            <td>
                <?php echo $form['remarks']->renderLabel('Describe more...', array('class' => '')) ?>
            </td>
        </tr>
        <tr>
            <td><?php echo $form['remarks']->render(array('class' => 'data')); ?></td>
        </tr>
    </table>

    <?php echo $form['_csrf_token']->render(); ?>

    <br/>
    <div>
        <input type="submit" value="Save" class="btn-1 data" />
        <a id="cancel" class="btn-2" href="<?php echo $form->getObject()->isNew() ? $sf_request->getReferer() : url_for('data/showResearch?id='.$form->getObject()->id) ?>">Cancel</a>
    </div>
  
</form>